﻿using Dapper;
using Infrastructure.DataBaseConnect;
using Infrastructure.IRepository.overallAuth;
using Model.OverallAtuhModel;

namespace Infrastructure.Repository.overallAuth
{
    /// <summary>
    /// 菜单数据列仓储接口实现
    /// </summary>
    public class SysMenuTableColsRepository : Repository<SysMenuTableCols>, ISysMenuTableColsRepository
    {
        /// <summary>
        /// 根据菜单id和字段名称获取数据列
        /// </summary>
        /// <param name="menuId">菜单id</param>
        /// <param name="fieldName">字段名称</param>
        /// <returns>返回数据列</returns>
        public SysMenuTableCols? GetTableColsByMenuIdOrFieldName(string menuId, string fieldEnName)
        {
            string sql = @" select  * from  Sys_MenuTableCols where  MenuId =@MenuId and FieldEnName=@FieldEnName ";
            using var connection = DataBaseConnectConfig.GetSqlConnection();
            return connection.QueryFirstOrDefault<SysMenuTableCols>(sql, new { MenuId = menuId, FieldEnName = fieldEnName });
        }



        /// <summary>
        /// 修改字段信息
        /// </summary>
        /// <param name="sysMenuTableCols"></param>
        public void UpdateTableCols(SysMenuTableCols sysMenuTableCols)
        {
            string sql = @" update  Sys_MenuTableCols set  FieldCnName = @FieldCnName,FieldEnName=@FieldEnName,FieldType=@FieldType  where  FieldId = @FieldId ";
            using var connection = DataBaseConnectConfig.GetSqlConnection();
            connection.Execute(sql, new { sysMenuTableCols.FieldId, sysMenuTableCols.FieldCnName, sysMenuTableCols.FieldEnName, sysMenuTableCols.FieldType });
        }

    }
}
